package com.juc;

import java.util.concurrent.CountDownLatch;

/**
 * 减法计数器
 *
 * @author hh
 * @since 2023/5/28
 */
public class CountDownLatchTest {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "go out");
                // 数量-1
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }

        // 等待计数器归零，然后再向下执行
        countDownLatch.await();

        System.out.println("close door");
    }
}
